package org.seefly.iprint.controller;

import org.seefly.iprint.entity.Helpinfo;
import org.seefly.iprint.entity.PageBean;
import org.seefly.iprint.service.HelpInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;


@RestController
@RequestMapping("/admin")
public class AdminInfoController {
    @Autowired
    private HelpInfoService service;
    @Value("${admin.queryType.helpInfo}")
    private String queryInfo;
    @Value("${admin.queryType.ads}")
    private String QueryAds;
    /**layui数据表格状态码*/
    @Value("${layui.status.success}")
    private String layuiTableStatus;


    @RequestMapping("/addInfo")
    public String addInfo(@RequestBody Helpinfo info) {
        //通过判断id是否有值决定更新或者插入
        System.out.println(info);
        service.addNew(info);
        return "OK";
    }
    
    
    @RequestMapping("/getInfoList")
    public PageBean<Helpinfo> getInfoList(Integer currPage, Integer pageSize, String queryType, String key) throws UnsupportedEncodingException{
        if(key != null && key != "") {
            key = new String(key.getBytes("ISO-8859-1"),"utf-8");
        }
        PageBean<Helpinfo> pb = service.findInfoList(currPage,pageSize,queryType,key);
        pb.setStatus(layuiTableStatus);
        return pb;
    }
    
    @RequestMapping("/getInfo")
    private Helpinfo getInfo(String id) {
        return service.getInfoById(id);
    }
    
    @RequestMapping("/delInfo")
    private String delInfoById(Integer id) {
        service.delInfoById(id);
        return "OK";
    }
}
